package org.finesys.system.convert;

import java.util.List;

import org.finesys.system.api.dto.SysUserDTO;
import org.finesys.system.api.entity.SysUser;
import org.finesys.system.api.vo.UserExcelVO;
import org.finesys.system.api.vo.UserVO;
import org.mapstruct.Builder;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * MapStruct对象转换方法
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE,builder = @Builder(disableBuilder = true))
public interface SysUserConvert {

    SysUserConvert INSTANCE = Mappers.getMapper(SysUserConvert.class);

    /**
     * 转换 SysUserDTO 为 SysUser 对象
     */
    SysUser convert(SysUserDTO sysUserDto);

    /**
     * 转换 SysUser 为  SysUserDTO 对象
     */
    @Mappings({
            @Mapping(target = "role", ignore = true),
            @Mapping(target = "post", ignore = true),
            @Mapping(target = "newPassword", ignore = true),
            @Mapping(target = "code", ignore = true),
            @Mapping(target = "perms", ignore = true)
    })
    SysUserDTO convert(SysUser sysUser);

    /**
     * 转换UserVO 为 SysUserDTO 对象
     */
    @Mappings({
            @Mapping(target = "params", ignore = true),
            @Mapping(target = "role", ignore = true),
            @Mapping(target = "post", ignore = true),
            @Mapping(target = "newPassword", ignore = true),
            @Mapping(target = "code", ignore = true),
            @Mapping(target = "perms", ignore = true),
            @Mapping(target = "columns", ignore = true)
    })
    SysUserDTO convert(UserVO userVO);

    /**
     * 转换 userExcelVO 为 SysUser 对象
     */
    @Mappings({
            @Mapping(target = "createBy", ignore = true),
            @Mapping(target = "updateBy", ignore = true),
            @Mapping(target = "updateTime", ignore = true),
            @Mapping(target = "params", ignore = true),
            @Mapping(target = "tenantId", ignore = true),
            @Mapping(target = "deptId", ignore = true),
            @Mapping(target = "password", ignore = true),
            @Mapping(target = "salt", ignore = true),
            @Mapping(target = "email", ignore = true),
            @Mapping(target = "sex", ignore = true),
            @Mapping(target = "loginIp", ignore = true),
            @Mapping(target = "lastLoginTime", ignore = true),
            @Mapping(target = "remarks", ignore = true),
            @Mapping(target = "passwordExpireDate", ignore = true),
            @Mapping(target = "userSn", ignore = true),
            @Mapping(target = "delFlag", ignore = true),
            @Mapping(target = "avatar", ignore = true),
            @Mapping(target = "isAdmin", ignore = true),
            @Mapping(target = "role", ignore = true),
            @Mapping(target = "post", ignore = true),
            @Mapping(target = "newPassword", ignore = true),
            @Mapping(target = "code", ignore = true),
            @Mapping(target = "perms", ignore = true),
            @Mapping(target = "columns", ignore = true)

    })
    SysUserDTO convert(UserExcelVO userExcelVO);

    /**
     * 转换 userExcelVO 为 SysUser 对象
     */
    @Mappings({
            @Mapping(target = "nickname", ignore = true),
            @Mapping(target = "tenantName", ignore = true),
            @Mapping(target = "roleNameList", ignore = true),
            @Mapping(target = "postNameList", ignore = true),
            @Mapping(target = "lineNum", ignore = true)
    })
    UserExcelVO convertExcelVO(UserVO userVO);

    /**
     * 数组转换
     */
    List<SysUserDTO> convertList(List<SysUser> list);

    /**
     * 分页对象转换
     */
    @Mappings({@Mapping(target = "optimizeJoinOfCountSql", ignore = true)})
    Page<SysUserDTO> convertPage(Page<SysUser> appDO);
}
